
package cn.dhnep.demo.controller;

import cn.dhnep.demo.pojo.Result;


import cn.dhnep.demo.pojo.entity.PackageOrder;
import cn.dhnep.demo.service.TbPackageOrderItemService;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import  org.springframework.web.bind.annotation.RestController;

/**
 * @Author 邱文彬
 * @Date 2021/11/19 9:48
 * @Version 1.0
 */

@RestController
public class PackageOrderItemController {


    @Autowired
    private TbPackageOrderItemService tbPackageOrderItemService;

    @ApiOperation(value = "按时间查询")
    @RequestMapping(value = "getDeliveryData", method = RequestMethod.POST)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Result getDeliveryData(@RequestParam("openId")
                                              String openId,
                                  @RequestParam(value = "startTime",
                                          required = false)
                                          String startTime,
                                  @RequestParam(value = "finishTime",
                                          required = false)
                                              String finishTime,
                                  @RequestParam(required = false)
                                              Integer code) {
        if (code == null && startTime.equals("") && finishTime.equals("")) {
            return new Result(0, "操作失败,时间与状态必填一位", null);
        }

        if (code != null) {
            if (code == 0) {
                return getHorsemanToday(openId);
            } else if (code == 1) {
                return getHorsemanThisWeek(openId);
            } else if (code == 2) {
                return getHorsemanThisMonth(openId);
            } else if (code == 3) {
                return getHorsemanThisYear(openId);
            }
        }

        PackageOrder packageOrder = tbPackageOrderItemService.getPackageOrderByTime(openId, startTime, finishTime);

        return new Result(0,"操作成功",packageOrder);
    }


    @ApiOperation(value = "今日")
    @RequestMapping(value = "getHorsemanToday", method = RequestMethod.POST)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Result getHorsemanToday(@RequestParam("openId") String openId) {

        PackageOrder packageOrder = tbPackageOrderItemService.getPackageOrderToday(openId);

        return new Result(0,"操作成功",packageOrder);
    }


    @ApiOperation(value = "近周")
    @RequestMapping(value = "getHorsemanThisWeek", method = RequestMethod.POST)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Result getHorsemanThisWeek(@RequestParam("openId") String openId) {

        PackageOrder packageOrder = tbPackageOrderItemService.getPackageOrderThisWeek(openId);

        return new Result(0,"操作成功",packageOrder);
    }



    @ApiOperation(value = "近月")
    @RequestMapping(value = "getHorsemanThisMonth", method = RequestMethod.POST)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Result getHorsemanThisMonth(@RequestParam("openId") String openId) {


        PackageOrder packageOrder = tbPackageOrderItemService.getPackageOrderThisMonth(openId);

        return new Result(0,"操作成功",packageOrder);
    }

    @ApiOperation(value = "近年")
    @RequestMapping(value = "getHorsemanThisYear", method = RequestMethod.POST)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    public Result getHorsemanThisYear(@RequestParam("openId") String openId) {

        PackageOrder packageOrder = tbPackageOrderItemService.getPackageOrderThisYear(openId);

        return new Result(0,"操作成功",packageOrder);
    }
}
